package org.spl.elevator.controller;

import java.util.ArrayList;
import org.spl.elevator.model.ElevatorDAO;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

public class ElevatorController {
	
	int speed;
	boolean dependence;
	int maxWeight;
	int password;
	String authorizationType;
	boolean externalDisplay;
	boolean internalDisplay;
	boolean powerRadio;
	FileInputStream in;
	
	public void configMove(ArrayList<ElevatorDAO> elevators){
		speed = 20; //Low Speed
		speed = 40; //Medium Speed
		speed = 60; //High Speed
		
		dependence = true; //Dependents elevators
		dependence = false; //Independents elevators
		
		for (int i = 0; i < elevators.size(); i++){
			elevators.get(i).setSpeed(speed);
			elevators.get(i).setDependence(dependence);
		}
	}
	
	public void configSecurity(ArrayList<ElevatorDAO> elevators){
		authorizationType = "panel";
		authorizationType = "apartment";
		for (int i = 0; i < elevators.size(); i++){
			askMaxWeight();
			elevators.get(i).setMaxWeight(maxWeight);
			askPassword();
			elevators.get(i).setPassword(password);
			elevators.get(i).setAuthorizationType(authorizationType);
		}
	}
	
	public void configMusic(ArrayList<ElevatorDAO> elevators){
		powerRadio = true;
		
		generatePlayList();
	}
	
	public void generatePlayList(){
		try {
			in = new FileInputStream("Musics/amongstthewaves.mp3");
			Player p = new Player(in);

			
			p.play();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (JavaLayerException e) {
				e.printStackTrace();
			}
	}
	
	public void askPassword(){
		/*
		 * TODO implementar pergunta da senha 
		 */
	}
	
	public void askMaxWeight(){
		//TODO implementar pergunta do peso m�ximo na interface gr�fica
	}

	public void configExternalPanel(ArrayList<ElevatorDAO> elevators, int numButtons){
		externalDisplay = true;
		
		ExternalPanelController extPanel = new ExternalPanelController();
		
		extPanel.configPanel(elevators, numButtons);
	}
	
	public void configInternalPanel(ArrayList<ElevatorDAO> elevators, int numFloors, int maxSelectedButton){
		internalDisplay = true;
		
		InternalPanelController intPanel = new InternalPanelController();
		
		intPanel.configPanel(elevators, numFloors, maxSelectedButton);
	}
	
	public void configInternalPanel(ArrayList<ElevatorDAO> elevators, int numFloors){
		internalDisplay = true;
		
		InternalPanelController intPanel = new InternalPanelController();
		
		intPanel.configPanel(elevators, numFloors);
	}
}
